<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    欢迎，<span id="username"></span>
</div>
<button id="btnClear">清除本地存储</button>
</body>
<script>

    window.onload = function () {

        initWelcome();
        document.getElementById('btnClear').onclick = function () {
            localStorage.clear();
        }

    }

    function initWelcome() {

        var user=  localStorage.getItem("user");

        user = JSON.parse(user);// json反序列化，把字符串变成json对象

        document.getElementById('username').innerText = user.username;

    }

</script>
</html>